package com.itheima.wms.controller;

import com.itheima.wms.controller.vo.AreaAndLocationListVo;
import com.itheima.wms.controller.vo.AreaLocationTreeVo;
import com.itheima.wms.controller.vo.TreeAreaLocationVo;
import com.itheima.wms.pojo.CarrierPageDto;
import com.itheima.wms.pojo.Owner;
import com.itheima.wms.pojo.OwnerPageDto;
import com.itheima.wms.service.CarrierService;
import com.itheima.wms.service.OwnerService;
import com.itheima.wms.utils.PageBean;
import com.itheima.wms.utils.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/owner")
public class OwnerController {

    private final OwnerService ownerService;

    @GetMapping("/page")
    public Result<PageBean> ownerPage(OwnerPageDto ownerPageDto) {
        PageBean pageBean = ownerService.ownerPage(ownerPageDto);
        return Result.success(pageBean);
    }

    @PostMapping
    public Result ownerInsert(@RequestBody Owner owner) {
        log.info(owner.toString());
        ownerService.insert(owner);
        return Result.success("插入成功");
    }

    @GetMapping("/tree")
//    public Result<List<AreaLocationTreeVo>> ownerInsert(@RequestParam("仓库id") Long warehouseId) {
    public Result<AreaAndLocationListVo> ownerInsert(@RequestParam("仓库id") Long warehouseId) {
        log.info("仓库id为{}", warehouseId);
        AreaAndLocationListVo treeAreaLocationVo = ownerService.findTree(warehouseId);
        return Result.success(treeAreaLocationVo);
    }

    @GetMapping("/vague")
    public Result vagueQueryOwner(OwnerPageDto ownerPageDto) {
        List<Owner> ownerList = ownerService.vagueQueryOwner(ownerPageDto);
        return Result.success(ownerList);
    }
}
